<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('初始多表格')" />
	<style>
		.headerBox {
			margin-right: -15px;
			margin-left: -15px;
		}
		.input-time {
			width: 200px !important;
		}
		.labelBox {
			display: flex;
			align-items: center;
		}
		.labelBox select{
			height: 40px !important;
		}
	</style>
</head>
<body class="gray-bg">
<div class="container-div">

	<div class="row">
		<div class="col-sm-12 search-collapse">
			<p class="select-title">表格筛选</p>
			<form id="form1">
				<div class="select-list">
					<ul>
						<li>
							申请单位：<input type="text" name="applicationUnit"/>
						</li>
						<li>
							报检编号：<input type="text" name="inspectionNumber"/>
						</li>
						<li>
							处理范围：<input type="text" name="processRange"/>
						</li>
						<li>
							处理地点：<input type="text" name="processSites"/>
						</li>
						<li>
							使用药剂：
							<select id="medicineId" name="medicineId"  th:with="type=${@dict.getType('medicine')}">
								<option value="">全部</option>
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictCode}" ></option>
							</select>
						</li>
						<li>
							处理方式：
							<select id="processMethod" name="processMethod"  th:with="type=${@dict.getType('process_method')}">
								<option value="">全部</option>
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictCode}" ></option>
							</select>
						</li>
						<li>
							处理对象：<input type="text" name="processObject"/>
						</li>
						<li>
							报检编号：<input type="text" name="inspectionNumber"/>
						</li>
						<li>
							操作人员：<input type="text" name="operator"/>
						</li>
						<li>
							现场负责人：<input type="text" name="siteLeader"/>
						</li>
						<li>
							备注：<input type="text" name="remark"/>
						</li>
						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search('form1', 'bootstrap-table1')"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset('form1', 'bootstrap-table1')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
					</ul>
				</div>
			</form>
		</div>
		<div class="btn-group-sm" id="toolbar1" role="group">
			<a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="system:order:addView">
				<i class="fa fa-plus"></i> 新增
			</a>
			<a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="system:order:editView">
				<i class="fa fa-edit"></i> 修改
			</a>
			<a class="btn btn-danger multiple" onclick="$.operate.removeAll()" shiro:hasPermission="system:order:delete">
				<i class="fa fa-remove"></i> 删除
			</a>
			<a class="btn btn-success single disabled" onclick="print()" shiro:hasPermission="system:order:getById">
				<i class="fa fa-plus"></i> 打印
			</a>
			<a class="btn btn-success single disabled" onclick="$.operate.detailTab()" shiro:hasPermission="system:order:detailView">
				订单详情
			</a>
		</div>
		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table1"></table>
		</div>
	</div>
</div>

<div th:include="include :: footer"></div>
<th:block th:include="include :: lodop-js" />
<script th:inline="javascript">

	$(function() {
		var options = {
			id: "bootstrap-table1",
			uniqueId: 'id',
			formId: 'form1',
			toolbar: "toolbar1",
			url: "/order/list",
			createUrl: "/order/addView",
			removeUrl: "/order/deleteBatchByIds",
			updateUrl: "/order/editView",
			detailUrl: "/order/detailView",
			modalName: "单据",
			contentType: 'application/json; charset=utf-8',
			pageNumName: 'currentPage',
			ascName: 'asc',
			columns: [{
				checkbox: true
			},
				{
					field : 'companyName',
					title : '公司名'
				},
				{
					field : 'number',
					title : '编号'
				},
				{
					field : 'applicationUnit',
					title : '申请单位'
				},
				{
					field : 'inspectionNumber',
					title : '报检编号'
				},
				{
					field : 'processObject',
					title : '处理对象'
				},
				{
					field : 'processObjectId',
					title : '处理对象标识'
				},
				{
					field : 'processSites',
					title : '处理地点'
				},
				{
					field : 'processRange',
					title : '处理范围'
				},
				{
					field : 'processNumber',
					title : '处理方案编号'
				},
				{
					field : 'processNumberAliases',
					title : '处理方案编号别名',
					formatter: function(value, row, index) {
						return value || '-';
					}
				},
				{
					field : 'processMethod',
					title : '处理方式'
				},
				{
					field : 'usedElixir',
					title : '使用药剂'
				},
				{
					field : 'quantity',
					title : '数量/重量',
					formatter: function(value, row, index) {
						return row.firstQuantity + "×" + row.firstUnit + "  " + row.secondQuantity + "×" + row.secondUnit + "  " + row.thirdQuantity + "×" + row.thirdUnit;
					}
				},
				{
					field : 'totalMedication',
					title : '用药总量',
					formatter: function(value, row, index) {
						return value + row.totalMedicationUnit;
					}
				},
				{
					field : 'processTime',
					title : '处理时间',
					formatter: function(value, row, index) {
						return value + '小时';
					}
				},
				{
					field : 'temperature',
					title : '温度',
					formatter: function(value, row, index) {
						return value + '℃';
					}
				},
				{
					field : 'humidity',
					title : '湿度',
					formatter: function(value, row, index) {
						return value + '%';
					}
				},
				{
					field : 'windSpeed',
					title : '风速',
					formatter: function(value, row, index) {
						return value + 'm/s';
					}
				},
				{
					field : 'applicationStartTime',
					title : '施药开始时间',
					formatter: function(value, row, index) {
						return formatDate(value);
					}
				},
				{
					field : 'applicationEndTime',
					title : '施药结束时间',
					formatter: function(value, row, index) {
						return formatDate(value);
					}
				},
				{
					field : 'diffuseStartTime',
					title : '散气开始时间',
					formatter: function(value, row, index) {
						return formatDate(value);
					}
				},
				{
					field : 'diffuseEndTime',
					title : '散气结束时间',
					formatter: function(value, row, index) {
						return formatDate(value);
					}
				},
				{
					field : 'siteLeader',
					title : '现场负责人'
				},
				{
					field : 'operator',
					title : '操作人员'
				},
				{
					field : 'amount',
					title : '金额'
				},
				{
					field : 'area',
					title : '面积'
				},
				{
					field : 'volume',
					title : '体积'
				},
				{
					field : 'additionalBatcheNumber',
					title : '额外批次数量'
				},
				{
					field : 'remark',
					title : '备注'
				},
				{
					title: '操作',
					align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-info btn-xs href="javascript:void(0)" onclick="showPrint(\'' + row.id + '\')"><i class="fa fa-key"></i>打印</a>');
						return actions.join('');
					}
				}]
		};
		$.table.init(options);

	});

	function showPrint(id){
		$.get('/order/getById?id='+id, (res) => {
			print(res.data)
		});
	}

	var positionData = [[${@dict.getType('print_position')}]];
	var printData = {};
	positionData.forEach(item => {
		printData[item.dictValue] = item.remark.split(",");
	})

	function print(data) {
		if (!data) {
			data = $("#bootstrap-table1").bootstrapTable('getSelections')[0];
		}
		var LODOP=getLodop();
		LODOP.PRINT_INIT("打印");
		LODOP.ADD_PRINT_TEXT(+printData['companyName'][0],+printData['companyName'][1],+printData['companyName'][2],+printData['companyName'][3], data.companyName);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.ADD_PRINT_TEXT(+printData['number'][0],+printData['number'][1],+printData['number'][2],+printData['number'][3], data.number);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['applicationUnit'][0],+printData['applicationUnit'][1],+printData['applicationUnit'][2],+printData['applicationUnit'][3],"<p align=\"center\">"+ data.applicationUnit +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['inspectionNumber'][0],+printData['inspectionNumber'][1],+printData['inspectionNumber'][2],+printData['inspectionNumber'][3],"<p align=\"center\">"+ data.inspectionNumber +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['processObject'][0],+printData['processObject'][1],+printData['processObject'][2],+printData['processObject'][3],"<p align=\"center\">"+ data.processObject +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['processSites'][0],+printData['processSites'][1],+printData['processSites'][2],+printData['processSites'][3],"<p align=\"center\">"+ data.processSites +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		let mutliQuantity = '';
		if (data.firstQuantity && data.firstQuantity!= '0') {
			mutliQuantity += ((data.firstQuantity + "×" + data.firstUnit) + " ");
		}
		if (data.secondQuantity && data.secondQuantity!= '0') {
			mutliQuantity += ((data.secondQuantity + "×" + data.secondUnit) + " ");
		}
		if (data.thirdQuantity && data.thirdQuantity!= '0') {
			mutliQuantity += ((data.thirdQuantity + "×" + data.thirdUnit) + " ");
		}
		LODOP.ADD_PRINT_HTM(+printData['mutliQuantity'][0],+printData['mutliQuantity'][1],+printData['mutliQuantity'][2],+printData['mutliQuantity'][3],"<p align=\"center\">"+  mutliQuantity  +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['processRange'][0],+printData['processRange'][1],+printData['processRange'][2],+printData['processRange'][3],"<p align=\"center\">"+ data.processRange +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['processNumber'][0],+printData['processNumber'][1],+printData['processNumber'][2],+printData['processNumber'][3],"<p align=\"center\">"+ (data.processNumberAliases ? data.processNumberAliases : data.processNumber) +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_TEXT(+printData['processObjectId'][0],+printData['processObjectId'][1],+printData['processObjectId'][2],+printData['processObjectId'][3], data.processObjectId);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['usedElixir'][0],+printData['usedElixir'][1],+printData['usedElixir'][2],+printData['usedElixir'][3],"<p align=\"center\">"+ data.usedElixir +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['concentration'][0],+printData['concentration'][1],+printData['concentration'][2],+printData['concentration'][3],"<p align=\"center\">"+ data.concentration + data.concentrationUnit +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['totalMedication'][0],+printData['totalMedication'][1],+printData['totalMedication'][2],+printData['totalMedication'][3],"<p align=\"center\">"+ data.totalMedication + data.totalMedicationUnit +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['temperature'][0],+printData['temperature'][1],+printData['temperature'][2],+printData['temperature'][3],"<p align=\"center\">"+ data.temperature+"°，" + data.humidity +"%</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['applicationStartTime'][0],+printData['applicationStartTime'][1],+printData['applicationStartTime'][2],+printData['applicationStartTime'][3],"<p align=\"center\">"+ formatDate(data.applicationStartTime) +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['diffuseStartTime'][0],+printData['diffuseStartTime'][1],+printData['diffuseStartTime'][2],+printData['diffuseStartTime'][3],"<p align=\"center\">"+ (data.diffuseStartTime ? formatDate(data.diffuseStartTime) : '——') +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['applicationEndTime'][0],+printData['applicationEndTime'][1],+printData['applicationEndTime'][2],+printData['applicationEndTime'][3],"<p align=\"center\">"+ formatDate(data.applicationEndTime) +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['diffuseEndTime'][0],+printData['diffuseEndTime'][1],+printData['diffuseEndTime'][2],+printData['diffuseEndTime'][3],"<p align=\"center\">"+ (data.diffuseEndTime ? formatDate(data.diffuseEndTime) : '——') +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['siteLeader'][0],+printData['siteLeader'][1],+printData['siteLeader'][2],+printData['siteLeader'][3],"<p align=\"center\">"+ data.siteLeader +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['processTime'][0],+printData['processTime'][1],+printData['processTime'][2],+printData['processTime'][3],"<p align=\"center\">"+ data.processTime +"小时</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['windSpeed'][0],+printData['windSpeed'][1],+printData['windSpeed'][2],+printData['windSpeed'][3],"<p align=\"center\">"+ data.windSpeed +"m/s</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_HTM(+printData['operator'][0],+printData['operator'][1],+printData['operator'][2],+printData['operator'][3],"<p align=\"center\">"+ data.operator +"</p>");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.ADD_PRINT_TEXT(+printData['remark'][0],+printData['remark'][1],+printData['remark'][2],+printData['remark'][3], data.remark);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
		LODOP.PREVIEW();

	}
	function formatDate(date) {
		if (date){
			let day = date.split(" ")[0].split("-");
			let time = date.split(" ")[1].split(":");
			return day[0]+"年"+day[1]+"月"+day[2]+"日 "+time[0]+"时"+time[1]+"分";
		} else {
			return  '-'
		}

	}
</script>
</body>
</html>